package com.diaohw.module.system.controller;

import com.diaohw.module.system.mapper.AccountMapper;
import com.diaohw.module.system.obj.entity.Account;
import com.diaohw.module.system.service.AuthService;
import com.diaohw.platform.remote.auth.obj.bo.AccountInfoBO;
import com.diaohw.platform.remote.auth.obj.bo.AccountSaltBO;
import com.diaohw.platform.remote.auth.obj.bo.PasswordBO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Tag(name = "登录")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    AuthService service;
    @Resource
    private AccountMapper accountMapper;

    @GetMapping
    @Operation(summary = "根据用户名称查询")
    public List<AccountSaltBO> username(@RequestParam("username") String username) {
        return service.username(username);
    }

    @GetMapping("/{id}")
    @Operation(summary = "用户的所有信息")
    public AccountInfoBO accountInfo(@PathVariable("id") String id) {
        return service.info(id);
    }

    @PutMapping("/reset")
    @Operation(summary = "重置密码")
    public Boolean password(@RequestBody PasswordBO password) {
        return service.reset(password);
    }

    @GetMapping("/test")
    public Account test() {
        AccountInfoBO bo = new AccountInfoBO();
        bo.setLoginTime(LocalDateTime.now());
        return accountMapper.selectOneById("1810599181312606210");
    }
}
